package info.motteke.mybws.utils;

import java.io.PrintWriter;
import java.io.Writer;

/**
 * インデント機能を持つ{@linkplain PrintWriter}です。
 * 
 * @author YWak
 */
public class IndentablePrintWriter extends PrintWriter {

    private final String indent;

    private final String lineSeparator;

    private int indentLevel = 0;

    public IndentablePrintWriter(Writer out, String indent, String lineSeparator) {
        super(out);
        this.indent = indent;
        this.lineSeparator = lineSeparator;
    }

    @Override
    public void println() {
        print(lineSeparator);
    }

    public void increaseIndent() {
        indentLevel++;
    }

    public void decreaseIndent() {
        if (indentLevel > 0) {
            indentLevel--;
        }
    }

    public void indent() {
        for (int i = 0; i < indentLevel; i++) {
            print(indent);
        }
    }
}
